var commentList = new vo.newObj({
	parent:'#commentList',//事件绑定在父元素上,这样就可以动态添加子元素了,啊哈哈
	el:'#commentList',
	datas:{
	},
	methods:{
		flush:function(){
			ajax({
				method:'GET',
				url:'article/comment/list/'+id+"?"+Math.random(),
				success:function(resp){
					commentList.el.innerHTML = "";
					var datas = resp.datas;
					if(typeof(datas)!='undefined'){
						var length = datas.length;
						for(var i = 0;i<length;i++){
							commentList.el.innerHTML +=comment_list(datas[i],length-i);
						}
					}
				},error:function(){
					throw new Error("加载评论失败");
				}
			});
		},
		reply:function(){
			var t = target();
			var container = getElementsByAttr_r(this.el, "num", t.getAttribute("num"))[0];
			var reply = getElementsByAttr_r(container,"class","reply-comment")[0];
			if(reply.style.display == 'null' || reply.style.display == 'none'){
				reply.innerHTML = comment.el.innerHTML;
				if(null != t.getAttribute("uid")){
					reply.setAttribute("uid",t.getAttribute("uid"));
					var replyOne = t.parentNode.parentNode;
					var strs = getElementsByAttr_r(replyOne,"class","name|num");
					var name = strs[0].innerHTML+strs[1].innerHTML;
					reply.getElementsByTagName("textarea")[0]
						.value = "回复   "+name+": ";
				}else{
					reply.setAttribute("uid",container.getAttribute("uid"));
				}
				reply.style.display = 'inline-block';
			}else{
				reply.style.display = 'none';
				reply.innerHTML = "";
			}
		},
		send:function(){
			var t = target();
			if(t.getAttribute("class") == "send"){
				comment.methods.send(t.parentNode.parentNode);
			}
		},
		emoji:function(){
			var t = target();
			comment.methods.emoji(target().parentNode.parentNode,t);//直接调用comment对象的方法
		},
		toggle:function(){
			var t = target();
			if(t.getAttribute("class") == "emoji"){
				comment.methods.toggle(t.parentNode.parentNode);//直接调用comment对象的方法
			}
		}
	}
});
commentList.methods.flush();
var comment_list = function(){//写得真是他妈累
	var list = "<div class='comm_list' uid='#{id}' num='#{num}'>"+
			"<div class='comment-head'><img src='#{visitor.picpath}'/></div>"+
			"<div class='right'><span class='name'>#{visitor.nickname}</span>"+
			"<div class='comment-content'>#{content}</div>"+
			"<div class='tags'><div class='num'>#{num}</div>"+
			"<div class='date'>#{createTime}</div>"+
			"<div class='reply' num='#{num}' vo-m='click:reply'>回复</div>"+
			"</div>#{more}</div><div class='reply-comment' style='display:none'></div></div>";
	var inner = "<div class='row_list' uid='#{id}'>"+
			"<div class='head'><img src='#{visitor.picpath}'/></div>"+
			"<div class='inner-right'><div class='inner-content'>"+
			"<span class='name'>#{visitor.nickname}</span>#{content}"+
			"</div>"+
			"<div class='tags'><div class='num'>#{array}</div>"+
			"<div class='date'>#{createTime}</div><div class='reply' num='#{num}' uid='#{id}' vo-m='click:reply'>回复</div></div>"+
			"</div>"+
		"</div>";
	var reg = new RegExp("\\#{([\\S\\S]+?)}","g");
	function outer(data,num){
		return create(data,list,num);
	}
	function create(data,model,num){
		var copy = model;
		var result = copy.replace(reg,function($0,$1){
			if($1 == 'num'){
				return num+"楼";
			}else if($1 == 'createTime'){
				return typeof(data[$1]) == 'undefined'?"":
					new Date(parseInt(data[$1])).toLocaleString().replace(/:\d{1,2}$/,'');
			}else if($1.match(new RegExp("^visitor"))){
				var visitor = data["visitor"];
				var property = $1.substring(8);
				if(typeof(visitor) != 'undefined'){
					if(property == 'picpath'){
						return basepath+"f"+visitor['picpath'];
					}
					return visitor[property];
				}else{
					if(property == 'picpath'){
						return basepath+"resources/img/head.jpg";
					}else if(property == 'nickname'){ 
						return "匿名用户";
					}else{
						return "";
					}
				}
			}else if($1 == "more"){
				var innerList = data['list'];
				var innerHTML = ""; 
				if(typeof(innerList) != 'undefined'){
					for(var i = 0;i<innerList.length;i++){
						innerList[i]['array'] = '#'+(i+1);
						innerHTML+=(create(innerList[i],inner,num));
					}
				}
				return innerHTML;
			}else{
				return data[$1];
			}
		});
		return result;
	}
	return outer;
}();